package canglang.monitor.cases.dao;

import canglang.monitor.cases.model.CaseThreeModel;
import canglang.monitor.cases.to.SearchThreeTO;
import canglang.monitor.core.base.dao.BaseDAO;
import canglang.monitor.core.base.pagination.PaginatedListHelper;
import canglang.monitor.core.base.util.DateUtil;
import canglang.monitor.core.base.util.StringUtil;

import java.util.*;

@SuppressWarnings("unchecked")
public class CaseThreeDAO extends BaseDAO{
	public  Integer addCaseThree(CaseThreeModel caseThreeModel){
        String sql="addCaseThree";
        Map map=objectToMap(caseThreeModel);
        return (Integer)getSqlMapClientTemplate().insert(sql,map);
    }
	
	public CaseThreeModel getCaseThree(int caseThreeId){
        String sql="getCaseThree";
        Map map=new HashMap();
        map.put("caseThreeId", caseThreeId);
        return (CaseThreeModel)getSqlMapClientTemplate().queryForObject(sql,map);
    }
	
    public CaseThreeModel saveCaseThree(CaseThreeModel caseThreeModel){
        String sql="saveCaseThree";
        Map map=objectToMap(caseThreeModel);
        getSqlMapClientTemplate().update(sql,map);
        return this.getCaseThree(caseThreeModel.getCaseThreeId());
    }	
	
    public void deleteCaseThree(int caseThreeId){
        String sql="deleteCaseThree";
        Map map=new HashMap();
        map.put("caseThreeId", caseThreeId);
        getSqlMapClientTemplate().delete(sql,map);
    }


    public Integer searchCount(SearchThreeTO searchTO) {
        Map map = new HashMap();
        map.put("deptId", searchTO.getDeptId());
        map.put("dateFrom", searchTO.getDateFrom());
        if (searchTO.getDateTo() != null) {
            map.put("dateTo", DateUtil.add(searchTO.getDateTo(), Calendar.DATE, 1));
        }
        map.put("createId", StringUtil.convertEmpty2Null(searchTO.getCreateId()));
        return (Integer) getSqlMapClientTemplate().queryForObject("searchCaseThreeCount", map);
    }

    public List searchList(PaginatedListHelper helper, SearchThreeTO searchTO) {
        Map map = new HashMap();
        map.put("deptId", searchTO.getDeptId());
        map.put("dateFrom", searchTO.getDateFrom());
        if (searchTO.getDateTo() != null) {
            map.put("dateTo", DateUtil.add(searchTO.getDateTo(), Calendar.DATE, 1));
        }
        map.put("createId", StringUtil.convertEmpty2Null(searchTO.getCreateId()));        
        map = constructPaginationMap(helper, map);
        return getSqlMapClientTemplate().queryForList("searchCaseThreeList", map);
    }

     public List getCaseThreeList(SearchThreeTO searchTO) {
        Map map = new HashMap();
       // int deptId = searchTO.getDeptId();
        Date dateFrom = searchTO.getDateFrom();
        Date dateTo = searchTO.getDateTo();                 
       // map.put("deptId", deptId);
        map.put("dateFrom", dateFrom);
        if (dateTo != null) {
            map.put("dateTo", DateUtil.add(dateTo, Calendar.DATE, 1));
        }
        return getSqlMapClientTemplate().queryForList("getCaseThreeList", map);                                
    }
    public Integer getCaseThreeReportList(SearchThreeTO searchTO) {
        Map map = new HashMap();
        Date dateFrom = searchTO.getDateFrom();
        Date dateTo = searchTO.getDateTo();
        map.put("dateFrom", dateFrom);
        if (dateTo != null) {
            map.put("dateTo", DateUtil.add(dateTo, Calendar.DATE, 1));
        }

        String rank = searchTO.getRank();
        String industry = searchTO.getIndustry();
        String hotInd = searchTO.getHotInd();
        int ageFrom=searchTO.getAgeFrom();
        int ageTo=searchTO.getAgeTo();

        if (rank != null) {
            map.put("rank", rank);
        }
        if (industry != null) {
            map.put("industry", industry);
        }
        if (hotInd != null) {
            map.put("hotInd", hotInd);
        }

        if (ageFrom >0) {
            map.put("ageFrom", ageFrom);
        }
        if (ageTo>0) {
            map.put("ageTo", ageTo);
        }
        return (Integer) getSqlMapClientTemplate().queryForObject("getCaseThreeReportList", map);
    }
}
